home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / Pascal Demos / Button / Document.p < prev    next >
Text File  |  1996-01-24  |  3KB  |  135 lines

  1. unit Document;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types, Events, QuickDraw, Windows, Controls, TransSkel, ButtonGlobals;
  7.  
  8.  
  9.     procedure SetupDocument;
  10.  
  11. implementation
  12.  
  13.     const
  14.  
  15.         returnKey = chr(13);
  16.         enterKey = chr(3);
  17.         escapeKey = chr(27);
  18.  
  19.     var
  20.  
  21.         wind: WindowPtr;
  22.         okBtn: ControlHandle;
  23.         cancelBtn: ControlHandle;
  24.  
  25. {--------------------------------------------------------------------}
  26. { Window handling procedures }
  27. {--------------------------------------------------------------------}
  28.  
  29.  
  30.     procedure Mouse (pt: Point;
  31.                                     t: LongInt;
  32.                                     mods: Integer);
  33.         var
  34.             ctrl: ControlHandle;
  35.             partNo: Integer;
  36.     begin
  37.         partNo := FindControl(pt, wind, ctrl);
  38.         if (partNo <> 0) then
  39.             begin
  40. {$IFC OLDROUTINENAMES }
  41.                 if (partNo = inButton) then
  42. {$ELSEC}
  43.                 if (partNo = kControlButtonPart) then
  44. {$ENDC}
  45.                     begin
  46.                         if (TrackControl(ctrl, pt, nil) <> 0) then
  47.                             begin
  48.                                 { nothing done }
  49.                             end;
  50.                     end;
  51.             end;
  52.     end;
  53.  
  54.  
  55.     procedure Key (c: char;
  56.                                     code: Integer;
  57.                                     mods: Integer);
  58.     begin
  59.         if ((c = returnKey) or (c = enterKey)) then
  60.             begin
  61.                 if (okBtn^^.contrlHilite = normalHilite) then
  62.                     SkelFlashButton(okBtn);
  63.             end
  64.         else
  65.             begin
  66.                 if ((c = escapeKey) or SkelCmdPeriod(SkelGetCurrentEvent^)) then
  67.                     begin
  68.                         if (cancelBtn^^.contrlHilite = normalHilite) then
  69.                             SkelFlashButton(cancelBtn);
  70.                     end;
  71.             end;
  72.  
  73.     end;
  74.  
  75.  
  76.     procedure Update (resized: Boolean);
  77.         var
  78.             wind: WindowPtr;
  79.             r: Rect;
  80.             h: Integer;
  81.     begin
  82.         GetPort(wind);
  83.  
  84.         r := wind^.portRect;
  85.         EraseRect(r);
  86.         DrawControls(wind);
  87.         SkelDrawButtonOutline(okBtn);
  88.     end;
  89.  
  90.  
  91.     procedure Activate (active: Boolean);
  92.         var
  93.             hilite: Integer;
  94.     begin
  95.         if (active) then
  96.             hilite := normalHilite
  97.         else
  98.             hilite := dimHilite;
  99.         HiliteControl(okBtn, hilite);
  100.         SkelDrawButtonOutline(okBtn);
  101.         HiliteControl(cancelBtn, hilite);
  102.     end;
  103.  
  104.  
  105.     procedure Clobber;
  106.         var
  107.             wind: WindowPtr;
  108.     begin
  109.         GetPort(wind);
  110.         HideWindow(wind);
  111.         DisposeWindow(wind);
  112.     end;
  113.  
  114.  
  115.     procedure SetupDocument;
  116.         var
  117.             r: Rect;
  118.             ignore: Boolean;
  119.     begin
  120.  
  121.         if (SkelQuery(skelQHasColorQD) <> 0) then
  122.             wind := GetNewCWindow(docWindRes, nil, WindowPtr(-1))
  123.         else
  124.             wind := GetNewWindow(docWindRes, nil, WindowPtr(-1));
  125.         ignore := SkelWindow(wind, @Mouse, @Key, @Update, @Activate, nil, @Clobber, nil, false);
  126.         SetRect(r, 10, 20, 80, 40);
  127.         cancelBtn := NewControl(wind, r, 'Cancel', true, 0, 0, 1, pushButProc, 0);
  128.         OffsetRect(r, 80, 0);
  129.         okBtn := NewControl(wind, r, 'OK', true, 0, 0, 1, pushButProc, 0);
  130.  
  131.         ShowWindow(wind);
  132.         SkelDoEvents(activMask + updateMask);
  133.     end;
  134.  
  135. end.